package com.zmn.oms.dubbo.impl.wallquotation;

import com.alibaba.fastjson.JSON;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.oms.common.dio.wallquotation.WallOrderAmountDIO;
import com.zmn.oms.common.dro.wallquotation.WallOrderAmountDRO;
import com.zmn.oms.common.dro.wallquotation.WallQuotationDetailDRO;
import com.zmn.oms.common.dro.wallquotation.WallQuotationServItemDRO;
import com.zmn.oms.common.enums.WallTypeEnum;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.interfaces.wallquotation.WallQuotationListRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.zmn.business.interfaces.wallquotation.WallQuotationBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * 墙面订单远程服务
 *
 * @author chengguang
 * @date 2022/05/24
 */
@DubboService(version = DubboConsts.INTERFACE_VERSION, validation = "true")
@Slf4j
public class WallQuotationListRemoteServiceImpl implements WallQuotationListRemoteService {

    @Resource
    private WallQuotationBService wallQuotationBService;

    @Override
    @ReadOnlyConnection
    public ResponseDTO<WallQuotationServItemDRO> getWallQuotationServItemByOrderIdAndWorkId(Long orderId, Long workId) {

        try {
            log.info("WallQuotationBServiceImpl.getWallQuotationServItemByOrderIdAndWorkId,入参：orderId=[{}],workId=[{}],", orderId, workId);
            WallQuotationServItemDRO wallQuotationServItemDRO = wallQuotationBService.getWallQuotationServItemByOrderIdAndWorkId(orderId, workId);
            return ResponseDTO.success(wallQuotationServItemDRO);
        } catch (OmsBaseException e) {
            return ResponseDTO.fail(e.getMessage());
        } catch (Exception e) {
            log.error("根据订单id和工单id获取墙面价格信息失败,{}", e.getMessage(), e);
            return ResponseDTO.fail("根据订单id和工单id获取墙面价格信息失败");
        }
    }

    @Override
    @ReadOnlyConnection
    public ResponseDTO<WallQuotationDetailDRO> getWallQuotationDetailByOrderIdAndWorkId(Long orderId, Long workId) {

        try {
            log.info("[WallQuotationBServiceImpl.getWallQuotationDetailByOrderIdAndWorkId],入参：orderId=[{}],workId=[{}],", orderId, workId);
            WallQuotationDetailDRO wallQuotationDetailDRO = wallQuotationBService.getWallQuotationDetailByOrderIdAndWorkId(orderId, workId);
            return ResponseDTO.success(wallQuotationDetailDRO);
        } catch (OmsBaseException e) {
            return ResponseDTO.fail(e.getMessage());
        } catch (Exception e) {
            log.error("根据订单id获取墙面报价详细信息信息失败,{}", e.getMessage(), e);
            return ResponseDTO.fail("根据订单id获取墙面报价详细信息信息失败");
        }
    }

    @Override
    @ReadOnlyConnection
    public ResponseDTO<WallOrderAmountDRO> getWallOrderAmount(WallOrderAmountDIO wallOrderAmountDIO) {

        try {
            log.info("[WallQuotationBServiceImpl.getWallOrderAmount],入参：{},", JSON.toJSONString(wallOrderAmountDIO));
            WallOrderAmountDRO wallOrderAmount = wallQuotationBService.getWallOrderAmount(wallOrderAmountDIO);
            return ResponseDTO.success(wallOrderAmount);
        } catch (OmsBaseException e) {
            return ResponseDTO.fail(e.getMessage());
        } catch (Exception e) {
            log.error("WallQuotationListRemoteServiceImpl.getWallOrderAmount失败,{}", e.getMessage(), e);
            return ResponseDTO.fail("计算墙面订单价格和优惠信息失败");
        }
    }

    @Override
    @ReadOnlyConnection
    public ResponseDTO<WallTypeEnum> isWallQuotation(Long orderId, Long workId) {

        try {
            log.info("[WallQuotationBServiceImpl.isWallQuotation],入参：orderId=[{}],workId=[{}],", orderId, workId);
            return ResponseDTO.success(wallQuotationBService.isWallQuotation(orderId, workId));
        } catch (OmsBaseException e) {
            return ResponseDTO.fail(e.getMessage());
        } catch (Exception e) {
            log.error("查询是否墙面报价订单失败,{}", e.getMessage(), e);
            return ResponseDTO.fail("查询是否墙面报价订单失败");
        }
    }

}
